package com.taritari.journal.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.taritari.journal.entity.po.TreeHole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author taritari
 * @date 2024-01-18 15:59
 * @description 树洞
 */
@Mapper
public interface TreeHoleMapper extends BaseMapper<TreeHole> {
    /**
     * 随机查询树洞内容
     * */
    TreeHole randomQueryTreeHole(String tag);
    /**
     * 查询用户是否点赞
     * */
    @Select("SELECT COUNT(*) FROM `userlike` WHERE user_id = #{userId} AND treehole_id = #{treeHoleId}")
    int queryUserLike(int userId,int treeHoleId);
    /**
     * 喜欢数改变
     * */
    int likesChanges(int number,int treeHoleId);
    /**
     * 添加用户喜欢表
     * */
    @Insert("INSERT INTO userlike VALUES(#{userId},#{treeHoleId},0);")
    int insertUserLike(int userId,int treeHoleId);
    /**
     * 删除用户喜欢表数据
     * */
    @Delete("DELETE FROM userlike WHERE user_id = #{userId} AND treehole_id = #{treeHoleId}")
    int deleteUserLike(int userId,int treeHoleId);
    /**
     * 查询用户喜欢的树洞id
     * */
    @Select("select treehole_id from userlike where user_id = #{userId} AND treehole_id != 0")
    List<Integer> queryUserLikeTreeHoldId(int userId);
    /**
     * 通过number获取id
     * */
    @Select("SELECT id FROM treehole WHERE number = #{number}")
    Integer  queryIdByJourNalNumber(String number);
}
